package com.huabo.contract.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.oracle.entity.TblLegalCloseinformation;
import com.huabo.contract.oracle.mapper.TblLegalCloseinformationMapper;
import com.huabo.contract.service.TblLegalCloseinformationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class TblLegalCloseinformationServiceImpl implements TblLegalCloseinformationService {

    @Resource
    private TblLegalCloseinformationMapper tblLegalCloseinformationMapper;

    @Override
    public String findListByPageInfo(PageInfo<TblLegalCloseinformation> pageInfo, TblLegalCloseinformation closeInfo,Integer disputeid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            String result = null;
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalCloseinformationMapper.findListByPageInfo(pageInfo, closeInfo, disputeid));
            pageInfo.setTotalRecord(tblLegalCloseinformationMapper.findListByPageInfoCount(closeInfo, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
            JSONObject jsonObject = new JSONObject(resultMap);
            result = jsonObject.toString();
            return result;
        } else {
            String result = null;
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalCloseinformationMapper.findListByPageInfo(pageInfo, closeInfo, disputeid));
            pageInfo.setTotalRecord(tblLegalCloseinformationMapper.findListByPageInfoCount(closeInfo, disputeid));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
            JSONObject jsonObject = new JSONObject(resultMap);
            result = jsonObject.toString();
            return result;
        }
    }

    @Override
    public TblLegalCloseinformation findById(Integer closeId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblLegalCloseinformationMapper.findByCloseId(closeId);
        } else {
            return tblLegalCloseinformationMapper.findByCloseId(closeId);
        }
    }

    @Override
    public void addDisputeSettlement(TblLegalCloseinformation closeInfo) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalCloseinformationMapper.addDisputeSettlement(closeInfo);
        } else {
            tblLegalCloseinformationMapper.addDisputeSettlement(closeInfo);
        }
    }

    @Override
    public void updateModifyDisputeSettlementModify(TblLegalCloseinformation oldCloseInfo) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalCloseinformationMapper.updateModifyDisputeSettlementModify(oldCloseInfo);
        } else {
            tblLegalCloseinformationMapper.updateModifyDisputeSettlementModify(oldCloseInfo);
        }
    }

    @Override
    public void removeDisputeSettlementRemove(Integer closeid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            tblLegalCloseinformationMapper.removeDisputeSettlementRemove(closeid);
        } else {
            tblLegalCloseinformationMapper.removeDisputeSettlementRemove(closeid);
        }
    }
}
